package API.DAY9.thread;

public class SyncDemo4 {
    public static void main(String[] args) {
        boo b = new boo();
        new Thread(b::methoda).start();
        new Thread(b::methodb).start();
    }
}
class boo{
//    public synchronized void methoda(){
    public void methoda(){
        synchronized (this) {
            Thread t = Thread.currentThread();
            System.out.println(t.getName() + "开始...");

            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(t.getName() + "结束...");
        }
    }
//    public synchronized void methodb(){
    public void methodb(){
        synchronized (this) {
            Thread t = Thread.currentThread();
            System.out.println(t.getName() + "开始...");

            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(t.getName() + "结束...");
        }
    }
}